package com.fancy.learncenter.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.fancy.learncenter.R;

/**
 * Created by shiweiwei on 2018/1/15.
 */

public class CartoonFinishWorkTurnipNumView extends LinearLayout{
    private Context mContext;
    private View rootView;
    private int turnipNum;
    private ImageView imageView1;
    private ImageView imageView2;
    private ImageView imageView3;
    private ImageView imageView4;
    private ImageView imageView5;

    public CartoonFinishWorkTurnipNumView(Context context) {
        super(context);
        this.mContext =context;
        initView();
    }

    public CartoonFinishWorkTurnipNumView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView();
    }


    /**
     * 设置萝卜数量
     * @param turnipNum
     */
    public void setTurnipNum(int turnipNum) {
        this.turnipNum = turnipNum;
        setData(turnipNum);
    }

    private void initView(){ 

        rootView = LayoutInflater.from(mContext).inflate(R.layout.cartoon_finish_work_turnip_view,this);
        imageView1 = (ImageView) rootView.findViewById(R.id.turnip_image_1);
        imageView2 = (ImageView) rootView.findViewById(R.id.turnip_image_2);
        imageView3 = (ImageView) rootView.findViewById(R.id.turnip_image_3);
        imageView4 = (ImageView) rootView.findViewById(R.id.turnip_image_4);
        imageView5 = (ImageView) rootView.findViewById(R.id.turnip_image_5);
        setData(turnipNum);
    }

    private void setData(int turnipNum){
        switch (turnipNum){

            case 0:
                imageView1.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView2.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView3.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView4.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView5.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                break;
            case 1:
                imageView1.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView2.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView3.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView4.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView5.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                break;
            case 2:
                imageView1.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView2.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView3.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView4.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView5.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                break;
            case 3:
                imageView1.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView2.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView3.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView4.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                imageView5.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                break;
            case 4:
                imageView1.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView2.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView3.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView4.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView5.setImageResource(R.mipmap.cartoon_finish_work_turnip_gray);
                break;
            case 5:
                imageView1.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView2.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView3.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView4.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                imageView5.setImageResource(R.mipmap.cartoon_finish_work_turnip_light);
                break;
        }
    }


}
